<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>轻时光微信打印机5.0</title>
    <meta name="keywords" content=轻时光微信打印机5.0">
    <meta name="description" content="轻时光微信打印机5.0">

    <link rel="shortcut icon" href="favicon.ico"> <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__CSS__/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__CSS__/animate.min.css" rel="stylesheet">
    <link href="__CSS__/style.min.css?v=4.1.0" rel="stylesheet">
    <script language="javascript" src="__JS__/plugins/lodop/LodopFuncs.js"></script>

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="row animated fadeInRight">
            <div class="col-sm-4">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>扫一扫打印美照</h5>
                    </div>
                    <div>
                    {volist name="printers" id='printer'}
                        <div align="center" class="ibox-content no-padding border-left-right" >
                        <img alt="image" class="img-responsive" width="50%"  src="{$printer.qrcode}">
                        </div>
                        </hr>
                        <h3 align="center">{$printer.title}</h3>
                        </hr>
                    {/volist}
                       
                    </div>
                </div>
            </div>

            <div class="col-sm-4">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>正在打印</h5>
                    </div>
                    <div>
                        <div class="ibox-content no-padding border-left-right" id= 'printting'>
                            <img alt="image" class="img-responsive" src="__IMG__/ad.jpg">
                        </div>
                        
                    </div>
                </div>
            </div>
            <div class="col-sm-4">


                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>TA们正在排队</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="profile.html#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="profile.html#">选项1</a>
                                </li>
                                <li><a href="profile.html#">选项2</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">

                        <div>
                            <div class="feed-activity-list" id="pics">

                                <div class="feed-element">
                                    <a href="profile.html#" class="pull-left">
                                        <img alt="image" class="img-circle" src="__IMG__/profile.jpg">
                                    </a>
                                    <div class="media-body ">
                                        <small class="pull-right">5分钟前</small>
                                        <strong>faith</strong> 发送了一张美照
                                        <br>
                                        <small class="text-muted">今天 10:20 来自 iPhone 6 Plus</small>

                                    </div>
                                </div>
 

                            </div>

                            

                        </div>

                    </div>
                </div>

            </div>
        </div>
    </div>
    <script src="__JS__/jquery.min.js?v=2.1.4"></script>
    <script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
    <script src="__JS__/content.min.js?v=1.0.0"></script>
    <script src="__JS__/plugins/peity/jquery.peity.min.js"></script>
    <script src="__JS__/demo/peity-demo.min.js"></script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>

</body>
</html>



<script language="javascript" type="text/javascript">   
var LODOP,P_ID='',StatuMessage,waiting=false,loop=0; //声明为全局变量 
setInterval(function(){
var  html ="";
$("#pics").html('');
$.ajax({
    type:"post",
    url:"{:url('getPics')}",
    data:{ shopid:"{$shopid}"},
    dataType:"text",
    success:function(data){
      if(data){
         var pics = JSON.parse(data); 
         $.each(pics, function(i) {
         LODOP=getLodop();
         var StatuMessage=getStatuMessage(LODOP.GET_VALUE('PRINT_STATUS_ID',pics[i].P_ID));
         if ( StatuMessage==""){
         StatuMessage="排队中";
         }else{
         $("#printting").html('<img alt="image" class="img-responsive"  width="100%" src="'+ pics[i].url+'">'); 
        }
        html = '<div class="feed-element"><a href="profile.html#" class="pull-left"><img alt="image" class="img-circle" src="__IMG__/profile.jpg"></a> <div class="media-body "><small class="pull-right">'+StatuMessage+'</small><strong>'+pics[i].nickname+'</strong> 发送了一张美照<br><small class="text-muted">'+pics[i].create_time+'来自 iPhone 6 Plus</small></div></div>';
       
        $("#pics").html(html);

         if (pics[i].status==0) {
                PrintWait(pics[i].id,pics[i].url,pics[i].nickname);//推入打印机
            }else{
                if ((LODOP.GET_VALUE('PRINT_STATUS_ID',pics[i].P_ID) & 128 )|| LODOP.GET_VALUE('PRINT_STATUS_EXIST',pics[i].P_ID) ==0) { 
                    okAjax(pics[i].id,'2',pics[i].P_ID); //表示打印真正结束啦
                }
         }
        });
     }
    },
    async:true
  });
  } ,3000);


  var  okAjax = function(id,status,P_ID){
  
   $.ajax({
    type:"post",
    url:"{:url('printStatus')}",
    data:{id:id,status:status,P_ID:P_ID},
    dataType:"text",
    success:function(data){
      if(data){
      var json = JSON.parse(data); //数组  
      console.log(json);
      }
       
    },
    async:false
  });
}

   function PrintWait(id,url,admin){
        LODOP=getLodop();  
        LODOP.PRINT_INIT(admin + "照片");
        LODOP.ADD_PRINT_IMAGE(3,0,320,500,'<img border="0" src="'+url+'" />');
        
        LODOP.SET_PRINT_STYLEA(0,"Stretch",2);//按原图比例(不变形)缩放模式
        LODOP.SET_PRINT_MODE("CATCH_PRINT_STATUS",true);
        P_ID=LODOP.PRINT(); 
        if (P_ID!=""){
        okAjax(id,'1',P_ID);
        console.log(id,P_ID);
        }
         
      }
    
    
   function getStatuMessage(statusID,pid) { 
    var messages="";
    if (statusID & 0) messages += "等待打印 -";
    if (statusID & 1) messages += "已暂停 -";
    if (statusID & 2) messages += "错误 -";
    if (statusID & 4) messages += "打印机 -";
    if (statusID & 8) messages += "进入队列 -";
    if (statusID & 16) messages += "正在打印 -";
    if (statusID & 32) messages += "脱机 -";
    if (statusID & 64) messages += "缺纸 -";
    if (statusID & 128) messages += "打印结束 -";
    if (statusID & 256) messages += "已删除 -";
    if (statusID & 512) messages += "堵了 -";
    if (statusID & 1024) messages += "用户介入 -";
    if (statusID & 2048) messages += "正在重新启动 -";
    return messages;
  }


</script> 